import 'package:flutter/material.dart';

class Cell extends StatelessWidget {
  final String title;
  final String? routePath;
  final Function? routeAction;
  final Widget? routePage;
  final String? routeName;

  void _onPressed(BuildContext context) {
    if (null != routeAction) {
      routeAction!.call();
      return;
    }
    if (null != routePage) {
      Navigator.push(context, MaterialPageRoute(builder: (builder)=> routePage!));
      return;
    }
    if (null != routeName) {
      Navigator.pushNamed(context, routeName!);
      return;
    }
  }

  const Cell({
    Key? key,
    required this.title,
    this.routePath,
    this.routeAction,
    this.routePage,
    this.routeName,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: TextButton(
        onPressed: () => _onPressed(context),
        style: ButtonStyle(
          padding: MaterialStateProperty.all(const EdgeInsets.symmetric(vertical: 0, horizontal: 15)),
        ),
        child: Row(
          children: [
            Text(title),
            const Spacer(),
            const Icon(Icons.arrow_right, color: Colors.grey,)
          ],
        ),
      ),
      decoration: const BoxDecoration(
        border: Border(bottom: BorderSide(color: Colors.teal, width: 0.5)),
      ),
    );
  }
}
